// Naive.expose("login", async function (ctx,pck) {
//     console.log(`pck:${pck}`);
//     let next = new Promise(async(res)=>{
//         let login = Naive.expose((ctx,pck)=>{
//             console.log(`login as ${pck.username}`);
//             res(ctx);
//         });
//         let register=Naive.expose(async (ctx,pck)=>{
//             console.log("register");
//             let form=await ctx.invoker.interact("input",{url:"register.xml"});
//             console.log(`register as ${form.username}`);
//             res(ctx);
//         });
//         let forget=Naive.expose(async (ctx, pck)=>{
//             console.log("forget");
//             let form=await ctx.invoker.interact("input",{url:"forget.xml"});
//             if (form.vCode!="123456") return;
//             let pswd=await ctx.invoker.interact("input", {url:"inputNewPswd.xml"});
//             console.log(`new pswd:${pswd}`);
//             res(ctx);
//         })
//         await ctx.invoker.interact("redirect",{url:"login.xml",next:{login,register}});
//     });
//     ctx.invoker.interact("finish",{});
//
//     let userCtx = await next;
//     await userCtx.invoker.interact("wsconnect", "some_token");
//     let chanceResult=await Naive.invoke(`chance://some_token/sendMessage`,{message:"hello world!"});
//     await ctx.invoker.interact("store", {username:"134682863600", token:"some_token"});
//     await ctx.invoker.interact("finish",{});
//     console.log("login finished");
// });
//
// Naive.expose("test", async (ctx, pck)=>{
//     console.log("step 1",pck.hello);
//     let p=await ctx.invoker.interact("retrieve",{hello:"new"});
//     console.log("interact retrieve:",p);
//     ctx.invoker.interact("finish", {done:`good ${+pck.hello}`});
// });
//
//
// async function test2(){
//     let a=await Naive.invoke(`chance://a/sendMessage`,{message:"hello world!"});
//     console.log(`invoke result:${a}`);
// }
// test2();

events.listen({type:"network", address:"init"}, ()=>{
    let a=0;
    events.listen({type:"network", address:"A"}, ()=>{console.log(a); a+=1;});
    events.listen({type:"network", address:"B"}, ()=>{console.log(a); a-=1;});
});